git恢复本地文件 |
您所在的位置:网站首页 › git checkout 恢复文件 › git恢复本地文件 |
背景
项目管理过程中,有时候会误删文件,此时使用git pull没办法恢复。那有没有什么办法可以像svn那样,把当前缺失的文件一把恢复呢?答案是肯定的。 解决手段1、恢复单个文件 如果删除的只是某个文件,处理方式很简单,直接checkout即可, git checkout -- file其中,checkout后面两个-,是为了防止刚好有个分支名字为file。 如果删除的文件很多呢,总不可能一个个找出来checkout吧。。。 2、恢复多个文件 其实思想倒还真是一个个找出来,只不过git有命令帮我们找而已。 git ls-files -d | xargs git checkout --使用git ls-files可以查看本地被删除的文件,然后管道交给checkout批量处理。 除了查看删除的文件,还可查看当前修改的文件,我们可以看下git ls-files的帮助信息, SYNOPSIS git ls-files [-z] [-t] [-v] (--[cached|deleted|others|ignored|stage|unmerged|killed|modified])\* (-[c|d|o|i|s|u|k|m])\* [-x |--exclude=] [-X |--exclude-from=] [--exclude-per-directory=] [--exclude-standard] [--error-unmatch] [--with-tree=] [--full-name] [--abbrev] [--] []\* OPTIONS -c, --cached Show cached files in the output (default) -d, --deleted Show deleted files in the output -m, --modified Show modified files in the output -o, --others Show other (i.e. untracked) files in the output -i, --ignored Show only ignored files in the output. When showing files in the index, print only those matched by an exclude pattern. When showing "other" files, show only those matched by an exclude pattern. |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |